package cn.tedu.baking.service.impl;

import cn.tedu.baking.mapper.BannerMapper;
import cn.tedu.baking.pojo.vo.BannerAdminVO;
import cn.tedu.baking.pojo.vo.BannerIndexVO;
import cn.tedu.baking.service.IBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.util.List;

@Service
public class BannerService implements IBannerService {
    @Autowired
    BannerMapper bannerMapper;
    @Override
    public List<BannerIndexVO> selectIndex() {
        return bannerMapper.selectIndex();
    }

    @Override
    public List<BannerAdminVO> listForAdmin() {
        return bannerMapper.selectForAdmin();
    }

    @Value("${file-path}")
    private String dirPath;
    @Override
    public void deleteById(Integer id) {
        String imgUrl = bannerMapper.selectUrlById(id);
        new File(dirPath+imgUrl).delete();
        bannerMapper.deleteById(id);
    }
}
